<template>
   <we-table-dynamic
                      :columns="tableColumns"
                      :loading="tabLoading"
                      :props="tableProps"
                      @cell-click="handleCellClick"
                      @row-click="handleCellClick"
                      ref="cRef"
              >
                  <!-- <div slot="append">测试slot append</div> -->
              </we-table-dynamic>
</template>

<script>
  import genFormItem from './gen.js';
	export default {
    computed:{
      tableProps(){
          return {
            'highlight-current-row': true,
            size: 'large',
            'header-cell-class-name': "we-table-header-cell",
            'cell-class-name': "we-table-cell",
            border: true,
            style: "width: 100%;",
            data: this.confList
          }
        },
    },
    data(){
     return {
        tabLoading: false,
        tableColumns:[
          {
            label: '编号',
            prop: 'id',
            width: '100'
          },
          {
              label: '默认体检医生',
              prop: 'isPeDoc',
              minWidth: '200px',
              renderCell: (h, {row,column,$index}) => {
                return {
                  type: 'switch',
                  model: this.confList[$index]
                }
            }
          },
          {
            label: '操作',
            width: '200px',
            fixed: "right",
            renderCell: (h, {row,column,$index}) => {
              let type = 'button';
              let editOpts = {
                  events: {
                    click:() => {
                      this.handleTableOprate({ type: 'update', row })
                    }
                  }, 
                  props:{
                    type:"text",
                    size:"small"
                  },
                  text: '编辑'
                }
              let deleteOpts = {
                  events: {
                    click:() => {
                      this.handleTableOprate({ type: 'delete', row })
                    }
                  }, 
                  props:{
                    type:"text",
                    size:"small"
                  },
                  text: '删除'
              }
              let children = [];
              
                children.push(genFormItem(type,h)( editOpts));
             
                children.push(genFormItem(type,h)( deleteOpts));

              return h('div', {
              },children)
            } // 这是自定义的El-Table-column Attributes，对应scopedSlot!!!
          }
        ],
        confList: [{
            id: 1,
            title: 1,
            name: '王志远',
            isPeDoc: true
          }]
     }
      
    },
    methods: {
       handleCellClick(...args) {
     	 	console.log(args)
   		 },
      handleTableOprate (its) {
      const type = its.type;
      switch (type) {
        case 'add':
          
          break;
        case 'update':
          
          break;
        case 'delete':
        
          break;
        default:
          return '';
      }
      return false;
    }
    }
  }
</script>
<style>

</style>